package main

import (
	"fmt"
	"strings"
)

type myFunc func(i1 int, i2 int) int

func sum(i1 int, i2 int) int {
	return i1 + i2
}

func minus(i1 int, i2 int) int {
	return i1 - i2
}

func SumAndMinus(i1 int, i2 int, sum myFunc, minus myFunc) (int, int) {
	return sum(i1, i2), minus(i1, i2)
}

// 闭包
func MakeSuffix(suffix string) func(filename string) string {
	return func(filename string) string {
		if !strings.HasSuffix(filename, suffix) {
			return filename + suffix
		}
		return filename
	}
}

func main() {

	fmt.Printf("sum的类型是: %T\n", sum)

	var a = sum
	fmt.Println(a(1, 2))

	i1 := 10
	i2 := 20

	s, m := SumAndMinus(
		i1, i2, sum,
		// 匿名函数
		func(i1 int, i2 int) int {
			return i1 - i2
		})
	fmt.Println(s, m)

	// 类型别名
	type myInt int
	var num1 myInt
	var num2 int
	num1 = 40
	num2 = int(num1)
	fmt.Println(num2)

	// 闭包
	f := MakeSuffix(".jpg")
	name := f("1")
	fmt.Println(name)
}
